package com.gitee.pifeng.monitoring.example;

import com.gitee.pifeng.monitoring.common.constant.AlarmLevelEnums;
import com.gitee.pifeng.monitoring.common.constant.MonitorTypeEnums;
import com.gitee.pifeng.monitoring.common.constant.ThreadTypeEnums;
import com.gitee.pifeng.monitoring.common.domain.Alarm;
import com.gitee.pifeng.monitoring.common.domain.Result;
import com.gitee.pifeng.monitoring.plug.Monitor;
import com.google.common.base.Charsets;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main {

    public static void main(String[] args) {

        // 开启监控功能
        Monitor.start();

        // 业务埋点监控
        ScheduledExecutorService service = Monitor.buryingPoint(() -> {
            // 如果发现业务异常，则发送告警
            Alarm alarm = Alarm.builder()
                    .alarmLevel(AlarmLevelEnums.ERROR)
                    .title("业务埋点监控")
                    .isTest(false)
                    .charset(Charsets.UTF_8)
                    .msg("测试普通maven程序业务埋点监控！")
                    .monitorType(MonitorTypeEnums.CUSTOM)
                    .build();
            Result result = Monitor.sendAlarm(alarm);
            System.out.println("发送业务告警结果：" + result.toJsonString());
        }, 0, 1, TimeUnit.HOURS, ThreadTypeEnums.IO_INTENSIVE_THREAD);
        System.out.println(service.toString());

        // 防止主线程退出（测试代码才需要）
        while (true) {
        }
    }

}
